using System;
using System.ServiceModel.DomainServices.Client;
using System.Windows.Input;
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;

namespace ErickOrlando.Utilidades.Mvvm
{
	/// <summary>
	/// Clase que permite crear Objetos ViewModel Complejos
	/// </summary>
	/// <typeparam name="TEdit">Tipo de ComplexClass que manejara el mantenimiento</typeparam>
	/// <typeparam name="TList">Tipo de ComplexClass que manejara los datos de Lista</typeparam>
	public class ViewModelComplex<TEdit, TList> : ViewModelBase
		where TEdit : ComplexClass
		where TList : ComplexClass
	{

		#region Variables
		private TEdit _editable;
		private TList _lista;
		#endregion

		#region Propiedades
		/// <summary>
		/// Obtiene la propiedad del objeto Editable.
		/// </summary>
		public TEdit Editable
		{
			get { return _editable; }
			set
			{
				_editable = value;
				RaisePropertyChanged("Editable");
			}
		}

		/// <summary>
		/// Obtiene la propiedad del objeto Lista
		/// </summary>
		public TList Lista
		{
			get { return _lista; }
			set
			{
				_lista = value;
				RaisePropertyChanged("Lista");
			}
		}
		#endregion

		#region Metodos Can
		public virtual bool CanExecuteCancel()
		{
			return Editable.IsCancelEnabled;
		}

		public virtual bool CanExecuteDelete()
		{
			return Editable.IsDeleteEnabled;
		}

		public virtual bool CanExecuteEdit()
		{
			return Editable.IsEditEnabled;
		}

		public virtual bool CanExecuteList()
		{
			return true;
		}

		public virtual bool CanExecuteNew()
		{
			return Editable.IsNewEnabled;
		}

		public virtual bool CanExecuteSave()
		{
			return Editable.IsSaveEnabled;
		}
		#endregion

		#region Metodos Execute
		public virtual void ExecuteCancel()
		{
			Editable.Cancel();
		}

		public virtual void ExecuteDelete()
		{
			Editable.Delete();
		}

		public virtual void ExecuteEdit()
		{
			Editable.Edit();
		}

		public virtual void ExecuteList()
		{
			Lista.List();
		}

		public virtual void ExecuteNew()
		{
			Editable.Create();
		}

		public virtual void ExecuteSave()
		{
			Editable.Save();
		}
		#endregion

		#region Commands
		public ICommand CancelCommand
		{
			get
			{
				return new RelayCommand(ExecuteCancel, CanExecuteCancel);
			}
		}

		public ICommand DeleteCommand
		{
			get
			{
				return new RelayCommand(ExecuteDelete, CanExecuteDelete);
			}
		}

		public ICommand EditCommand
		{
			get { return new RelayCommand(ExecuteEdit, CanExecuteEdit); }
		}

		public ICommand ListarCommand
		{
			get { return new RelayCommand(ExecuteList, CanExecuteList); }
		}

		public ICommand NewCommand
		{
			get
			{
				return new RelayCommand(ExecuteNew, CanExecuteNew);
			}
		}

		public ICommand SaveCommand
		{
			get
			{
				return new RelayCommand(ExecuteSave, CanExecuteSave);
			}
		}
		#endregion


	}
}
